﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DoeObjects;
using DoeLibsMVC.Models;
using DoeLibsMVC.Security;

namespace DoeLibsMVC.Controllers
{
    public class AuthorController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Get(int id)
        {
            ViewBag.authorId = id;
            return View();
        }

        [HttpGet]
        [Authorize(Roles = UserCategoryHelper.STAFF_CATEGORY)]
        public ActionResult Edit(int id)
        {
            Author author = Author.getByAid(id);
            ViewBag.authorId = id;

            if (author == null)
            {
                base.Message = new HttpMessage("No author for this authorId found", false);
                return RedirectToAction("Index", "Author");
            }
            else
            {
                EditAuthorModel eam = new EditAuthorModel();
                eam.Name = author.Name;

                return View(eam);
            }
        }
    }
}
